package com.example.homework;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.os.PersistableBundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

public class thirdActivity extends AppCompatActivity  implements  View.OnClickListener{
    private static final String TAG = "ttttt" ;
    int score1 = 0;
    int score2 = 0;

    /*hhhhhhhhhhhh*/

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_third2);
    }

    public void btnAdd3(View btn) {
        Log.i(TAG,"click");
        if (btn.getId() == R.id.btn3) {
            score1 += 3;
        } else if (btn.getId() == R.id.btn2) {
            score1 += 2;
        } else if (btn.getId() == R.id.btn1) {
            score1 += 1;
        } else {
            score1 = 0;
            score2 =0;
        }
        showScore();

    }
    private void showScore(){
        TextView show = findViewById(R.id.score1);
        show.setText(String.valueOf(score1));
        TextView show2= findViewById(R.id.score2);
        show2.setText(String.valueOf(score2));
    }


    public void btnAdd2(View btn) {
        Log.i(TAG,"click");
        if (btn.getId() == R.id.btn4) {
            score2 += 3;
        } else if (btn.getId() == R.id.btn5) {
            score2 += 2;
        } else if (btn.getId() == R.id.btn6) {
            score2 += 1;
        } else {
            score2 = 0;

        }
        showScore();
    }

    @Override
    public void onClick(View view) {

        score1=0;
        score2=0;
        showScore();
    }

    @Override
    public void onSaveInstanceState(@NonNull Bundle outState, @NonNull PersistableBundle outPersistentState) {
        super.onSaveInstanceState(outState, outPersistentState);
        outState.putInt("score1",score1);
        outState.putInt("score2",score2);
    }

    @Override
    protected void onRestoreInstanceState(@NonNull Bundle savedInstanceState) {
        super.onRestoreInstanceState(savedInstanceState);
        score1=savedInstanceState.getInt("score1",0);
        score2=savedInstanceState.getInt("score2",0);
        showScore();

    }
}


